﻿#region Copyright

// // The contents of this file are subject to the Mozilla Public License
// // Version 1.1 (the "License"); you may not use this file except in compliance
// // with the License. You may obtain a copy of the License at
// //   
// // http://www.mozilla.org/MPL/
// //   
// // Software distributed under the License is distributed on an "AS IS"
// // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// // License for the specific language governing rights and limitations under 
// // the License.
// //   
// // The Initial Developer of the Original Code is Robert Smyth.
// // Portions created by Robert Smyth are Copyright (C) 2008-2013.
// //   
// // All Rights Reserved.

#endregion

namespace NoeticTools.NWorkflow
{
    public interface IActivity
    {
        object SyncRoot { get; }

        /// <summary>
        ///     Cancel the activity, if any, started by the Begin call.
        /// </summary>
        /// <remarks>
        ///     Either Cancel or End is called when the activity has completed.
        /// </remarks>
        void Cancel();

        void OnEvent(object value);
    }

    public interface IActivity<T> : IActivity
    {
        /// <summary>
        ///     Perfrom final processing of results, if any, gathered during the action.
        /// </summary>
        /// <remarks>
        ///     Called after the activity started by Begin(..) has signalled completion.
        ///     Returns the result of the action. Writing to objects used in the
        ///     workflow should only occur within this method.
        ///     Either Cancel or End is called when the activity has completed.
        /// </remarks>
        T End();

        /// <summary>
        ///     Begin the action.
        /// </summary>
        /// <remarks>
        ///     Begins the activity. This may synchronous (blocking) or asynchronouse. The
        ///     action notifies the running of completion using the listener call-back.
        ///     The activity should not write to objects used in the workflow until
        ///     End() is called.
        /// </remarks>
        void Begin(IActivityListener<T> listener);
    }
}